<?php
class training 
{

public $max_weights = 10;
public $max_reps = 10;
public $max_time = 10;

  function __construct($user_info,$user_id) {
       //print "In constructor\n";
       $this->user_info = $user_info;
       $this->user_id = $user_id;
   }


    function weights_show_options ($weight = 0,$reps = 0,$dur = 0)
    {
    $self = URL_SELF;
        // make the form
        $output = '<form METHOD=post  ACTION="$self">';
        // select a weight
        $output .= '<br>Select a weight: <select name="weight">';
        
        $i = 1;
        while ($i <= $this->max_weights):         
            $weight_times_ten = $i * 10;
            if ($weight == $weight_times_ten) { $selected = ' SELECTED '; } else { $selected = ''; }
            $output .= '<option value="'.$weight_times_ten.'" '.$selected.'>'.$weight_times_ten.' kg</option>';
            $i++;
        endwhile;
        
        $output .= '</select>';
        $output .= '';
        $output .= '';

        // select a repitions
        $output .= '<br>Select amount of Reps: <select name="reps">';
        $i = 1;
        while ($i <= $this->max_reps):
            $reps_form = $i;
            if ($reps == $reps_form) { $selected = ' SELECTED '; } else { $selected = ''; }
            $output .= '<option value="'.$reps_form.'" '.$selected.'>'.$reps_form.' time(s)</option>';
            $i++;
        endwhile;
        $output .= '</select>';

        // select a duriation
        $output .= '<br>Duriation: <select name="dur">';
        $i = $this->max_time;
        while ($i > 0):
            $time_form = $i;
            if ($dur == $time_form) { $selected = ' SELECTED '; } else { $selected = ''; }
            $output .= '<option value="'.$time_form.'" '.$selected.'>'.$time_form.' minute(s)</option>';
            $i--;
        endwhile;
        $output .= '</select>';
        
        // end the form
        $output .= '<input type=hidden name=training value=1>';
        $output .= '<br><input type=submit value="Workout">';
        $output .= '</form>';
                
        return $output;
    }
    
    function weights_calculate_gain ($weight,$reps,$dur)
    {
    global $db;
        switch ($dur)
        {
            case 1:
                $time_bonus = 100;
            break;
            case 2:
                $time_bonus = 90;
            break;
            case 3:
                $time_bonus = 80;
            break;
            case 4:
                $time_bonus = 70;
            break;
            case 5:
                $time_bonus = 60;
            break;
            case 6:
                $time_bonus = 50;
            break;
            case 7:
                $time_bonus = 40;
            break;
            case 8:
                $time_bonus = 30;
            break;
            case 9:
                $time_bonus = 20;
            break;
             case 10:
                $time_bonus = 10;
            break;
           default:
              $time_bonus = 100;
        }
        
        if ($reps > 0 && $reps <= $this->max_reps) { $reps = $reps + '0.5'; } else {game_error('NP'); die(); exit(); }
        
        $strength_gain = (($weight * $reps/mt_rand(71,79)) + ($time_bonus/10))/10;
        $energy_loss = ($reps/10)*($time_bonus+$weight)*33.33333;
        $speed_gain = (0 - ($strength_gain/mt_rand(2,4)))/10;
        
        $sql = "UPDATE `user_stats` SET 
        `strength`=strength+'$strength_gain',
        `speed`=speed+'$speed_gain',
        `energy`=energy-'$energy_loss' WHERE `assoc_id`='$this->user_id'";
        
        //echo '<BR><pre>'.$sql .'</pre>';
        $db->query($sql);

        $reps = $reps - 0.5;

         $output = "<pre>You chose to lift a weight of $weight kg, 
        $reps times 
        in less than $dur minute of time.

 --

strength gained
        </pre>";
        
        // fix teh reps back to normal for the form
       $output .= $this->weights_show_options($weight,$reps,$dur);                
        return $output;
    }


}

?>